package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Class;
import com.ruoyi.system.service.IClassService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分类页面的内容模块Controller
 * 
 * @author ruoyi
 * @date 2022-12-08
 */
@Controller
@RequestMapping("/system/class")
public class ClassController extends BaseController
{
    private String prefix = "system/class";

    @Autowired
    private IClassService classService;

    @RequiresPermissions("system:class:view")
    @GetMapping()
    public String classify()
    {
        return prefix + "/class";
    }

    /**
     * 查询分类页面的内容模块列表
     */
    @RequiresPermissions("system:class:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Class classify)
    {
        startPage();
        List<Class> list = classService.selectClassList(classify);
        return getDataTable(list);
    }

    /**
     * 导出分类页面的内容模块列表
     */
    @RequiresPermissions("system:class:export")
    @Log(title = "分类页面的内容模块", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Class classify)
    {
        List<Class> list = classService.selectClassList(classify);
        ExcelUtil<Class> util = new ExcelUtil<Class>(Class.class);
        return util.exportExcel(list, "分类页面的内容模块数据");
    }

    /**
     * 新增分类页面的内容模块
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存分类页面的内容模块
     */
    @RequiresPermissions("system:class:add")
    @Log(title = "分类页面的内容模块", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Class classify)
    {
        return toAjax(classService.insertClass(classify));
    }

    /**
     * 修改分类页面的内容模块
     */
    @RequiresPermissions("system:class:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Class classify = classService.selectClassById(id);
        mmap.put("class", classify);
        return prefix + "/edit";
    }

    /**
     * 修改保存分类页面的内容模块
     */
    @RequiresPermissions("system:class:edit")
    @Log(title = "分类页面的内容模块", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Class classify)
    {
        return toAjax(classService.updateClass(classify));
    }

    /**
     * 删除分类页面的内容模块
     */
    @RequiresPermissions("system:class:remove")
    @Log(title = "分类页面的内容模块", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(classService.deleteClassByIds(ids));
    }
}
